/*Copyright (C) 2009 - 2011 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

short morp_verif_gagne(char matrice[10]) {
	short i;

	for(i = 0; i != 3; i++) {
		if(matrice[1 + (i*3)] == 'X' && matrice[2 + (i*3)] == 'X' && matrice[3 + (i*3)] == 'X')
			return 1;
		if(matrice[1 + (i*3)] == 'O' && matrice[2 + (i*3)] == 'O' && matrice[3 + (i*3)] == 'O')
			return 2;

		if(matrice[1 + i] == 'X' && matrice[4 + i] == 'X' && matrice[7 + i] == 'X')
			return 1;
		if(matrice[1 + i] == 'O' && matrice[4 + i] == 'O' && matrice[7 + i] == 'O')
			return 2;
	}

	if((matrice[1] == 'X' && matrice[5] == 'X' && matrice[9] == 'X') || (matrice[3] == 'X' && matrice[5] == 'X' && matrice[7] == 'X'))
		return 1;

	if((matrice[1] == 'O' && matrice[5] == 'O' && matrice[9] == 'O') || (matrice[3] == 'O' && matrice[5] == 'O' && matrice[7] == 'O'))
		return 2;

	return 0;
}
